using System;
using System.Collections.Generic;
using UnityEngine;
using Flaschengeist.Entities;

namespace Flaschengeist.Views 
{
	public class ScoreView : BaseView
	{	
		private IEnumerable<ScoreItem> score;
		private const int boxWidth = 350;		
		private const int boxHeight = 200;
		private Texture2D header;
		private Texture2D background;
		private GUISkin skin;
		
		void Start()
		{
			skin = (GUISkin)Resources.Load(Settings.GUI_SKIN_SMALL_TEXT);
			header = (Texture2D)Resources.Load("textures/gui_highscoreHeader");
			background = (Texture2D)Resources.Load("textures/gui_menuBackground");
		}
		
		public void UpdateScore(IEnumerable<ScoreItem> score)
		{
			this.score = score;
		}
						
		public void OnGUI()
		{	
			if (IsActive)
			{	
				GUI.skin = skin;
				GUI.DrawTexture(new Rect(Screen.width/2 - 163, Screen.height/2 - 115, 326, 320),background);
				GUI.DrawTexture(new Rect(Screen.width/2 - 163, Screen.height/2 - 250, 326, 198),header);
							
				int i = 1;
				foreach (ScoreItem item in score) 
				{
					GUI.Label(new Rect(Screen.width/2 - Settings.GUI_BUTTON_WIDTH/2, (Screen.height/2 - 70) + i * 18, Settings.GUI_BUTTON_WIDTH, Settings.GUI_BUTTON_HEIGHT), String.Format("{0}. {1}", i, item.PlayerName));
					GUI.Label(new Rect(Screen.width/2 - Settings.GUI_BUTTON_WIDTH/2 + 160, (Screen.height/2 - 70) + i * 18, Settings.GUI_BUTTON_WIDTH, Settings.GUI_BUTTON_HEIGHT), item.Score.ToString());
					i++;
				}
				
				if(GUI.Button(new Rect(Screen.width/2 - Settings.GUI_BUTTON_WIDTH/2, Screen.height/2 + 145, Settings.GUI_BUTTON_WIDTH, Settings.GUI_BUTTON_HEIGHT), "ok"))
				{			
					Hide();
					Close();
				}
			}
		}
				
		public event Action Close;
	}
}
